package org.hdax.service.impl;

import org.hdax.dao.UsersDao;
import org.hdax.entity.Users;
import org.hdax.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersDao usersDao;

    @Override
    public Users login(Users users) {
        return usersDao.getUsers(users.getUsername(),users.getPassword());
    }

    @Override
    public List<Users> getByPage(int offset, int limit, Users condition) {
        return usersDao.getByPageAndC(condition,offset,limit);
    }

    @Override
    public int getCount(Users condition) {
        return usersDao.getCountAndC(condition);
    }

    @Override
    public Users getById(Integer id) {
        return usersDao.getById(id);
    }

    @Override
    public boolean updateUsers(Users users) {
        boolean isUpdate = false;
        try {
            usersDao.updateEntity(users);
            isUpdate = true;
        }catch (Exception e){
            e.printStackTrace();
            isUpdate = false;
        }
        return isUpdate;
    }
}
